﻿using Framework.Utility.Helper;
using Framework.Utility.ViewModels;
using MySql.Data.MySqlClient;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MonitorCode.DBCode
{ 
    public class DBFactory
    {
        private static readonly object lockHelper = new object();
        private IDBService _service; 
        private DBLinkModel _model;

        public DBFactory(DBLinkModel model)
        {
            _model = model;
        }
        /// <summary>
        /// 执行一个增删改存储过程(有参)
        /// </summary>
        /// <param name="procName">存储过程名字</param>
        /// <param name="values">参数列表</param>
        /// <returns>影响行数</returns>
        public IDBService DBService()
        {
            if (_service == null)
            {
                lock (lockHelper)
                {
                    if (_service == null)
                    {
                        switch (_model.DBType.ToLower())
                        {
                            case "sqlserver":
                                _service = new SqlDBService(_model);
                                break;
                            case "mysql":
                                _service = new MySqlDBService(_model);
                                break;
                        }
                    }
                }
            }
            return _service;
        }
 
        //public static IDBService DBService
        //{
        //    get
        //    {
        //        if (_service == null)
        //        {
        //            lock (lockHelper)
        //            {
        //                if (_service == null)
        //                {
        //                    switch (_model.DBType)//GlobalContext.SystemConfig.CacheProvider
        //                    {
        //                        case "SqlServer":
        //                            _service = new SqlDBService(_model);
        //                            break;
        //                        case "MySql":
        //                            _service = new MySqlDBService(_model);
        //                            break;
        //                    }
        //                }
        //            }
        //        }
        //        return _service; 
        //    }
        //}
    }
}
